//
//  XMPayView.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/16.
//

#import "XMPayView.h"

@interface XMPayView ()

@property (nonatomic, strong) UILabel *payPriceLabel;

@end

@implementation XMPayView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    [self addSubview:self.navView];
    self.navTitleLabel.text = @"支付";
    self.backgroundColor = kColorHEX(0xF6F6F6);
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, kNavagationBarH + KScaleWidth(16.0), self.width, KScaleWidth(35.0)) font:KBoldFontSize(18.0) textColor:kColorHEX(0x333333) textAlignment:NSTextAlignmentCenter];
    titleLabel.text = @"芝麻盐儿平台商户订单";
    [self addSubview:titleLabel];
    [self addSubview:self.payPriceLabel];
    
    UIView *merchantBgView = [[UIView alloc] initWithFrame:CGRectMake(0, kNavagationBarH + KScaleWidth(105.0), self.width, KScaleWidth(70.0))];
    merchantBgView.backgroundColor = kColorHEX(0xffffff);
    [self addSubview:merchantBgView];
    UILabel *merchantTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(23.0), 0, merchantBgView.width/2 - KScaleWidth(23.0), merchantBgView.height) font:KFontSize(16.0) textColor:kColorHEX(0x999999)];
    merchantTitleLabel.text = @"商家";
    [merchantBgView addSubview:merchantTitleLabel];
    
    UILabel *merchantLabel = [[UILabel alloc] initWithFrame:CGRectMake(merchantBgView.width/2, 0, merchantBgView.width/2 - KScaleWidth(24.0), merchantBgView.height) font:KFontSize(16.0) textColor:kColorHEX(0x333333) textAlignment:NSTextAlignmentRight];
    merchantLabel.text = @"芝麻盐儿平台商户";
    [merchantBgView addSubview:merchantLabel];
    
    UIButton *payBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KBoldFontSize(17.0) frame:CGRectMake((self.width - KScaleWidth(320.0))/2, merchantBgView.maxY + KScaleWidth(32.0), KScaleWidth(320.0), KScaleWidth(44.0)) title:@"立即支付" titleColor:kColorHEX(0x333333)];
    [payBtn setGradientLayerWithLocations:@[@(0), @(1)] colors:@[(__bridge id)kColorHEX(0xFFD800).CGColor, (__bridge id)kColorHEX(0xFFE44E).CGColor] startPoint:CGPointMake(0.5, 0.37) endPoint:CGPointMake(0.5, 0.03)];
    [payBtn addTarget:self action:@selector(payAction:) forControlEvents:UIControlEventTouchUpInside];
    [payBtn setCornerRadius:payBtn.height/2];
    [self addSubview:payBtn];
}

- (void)setContentWithPayPrice:(NSString *)payStr {
    NSMutableAttributedString *priceAttr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%@", payStr] attributes:@{NSFontAttributeName : KBoldFontSize(26.0), NSForegroundColorAttributeName : kColorHEX(0x333333)}];
    [priceAttr addAttributes:@{NSFontAttributeName : KBoldFontSize(18.0)} range:NSMakeRange(0, 1)];
    [_payPriceLabel setAttributedText:priceAttr];
}

- (void)payAction:(UIButton *)button {
    self.payBlock ? self.payBlock() : nil;
}

#pragma mark - Init
- (UILabel *)payPriceLabel {
    if (!_payPriceLabel) {
        _payPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, kNavagationBarH + KScaleWidth(52.0), self.width, KScaleWidth(37.0)) font:KBoldFontSize(18.0) textColor:kColorHEX(0x333333) textAlignment:NSTextAlignmentCenter];
    }
    return _payPriceLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
